package com.ldu.exam.model;

import java.sql.Timestamp;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.UpdateTimestamp;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name="t_role")
public class RoleModel 
{
	@Id
	@Column(length=32)
//	@GeneratedValue(generator = "uuid")
//	@GenericGenerator(name = "uuid", strategy = "org.hibernate.id.UUIDGenerator")
	@GeneratedValue(strategy = GenerationType.IDENTITY,generator = "jpa-uuid")
	@GenericGenerator(name = "jpa-uuid",strategy = "uuid.hex")
	private String id ;
	
	/**
	 * 名称
	 */
	@Column(length=111,nullable=false,unique=true)
	private String name ;
	
	/**
	 * 停用 ( true : 停用 ; false or null : 启用 ; )
	 */
	private String suspended ;
	
	/**
	 * 摘要
	 */
	private String summary ;
	
	/**
	 * 账号
	 */
	@ManyToMany
	@JoinTable(
	      name="REL_ROLE_ACCOUNT",
	      joinColumns=@JoinColumn(name="ROLE_ID", referencedColumnName="ID"),
	      inverseJoinColumns=@JoinColumn(name="ACCOUNT_ID", referencedColumnName="ID"))
	@JsonIgnoreProperties(value = {"roles","cla","studentCla"})
	private Set<AccountModel> accounts;
	
	
//	/**
//	 * 资源
//	 */
//	@ManyToMany
//	@JoinTable(
//	      name="REL_ROLE_RESOURCE",
//	      joinColumns=@JoinColumn(name="ROLE_ID", referencedColumnName="ID"),
//	      inverseJoinColumns=@JoinColumn(name="RESOURCE_ID", referencedColumnName="ID"))
//	@JsonIgnoreProperties("roles")
//	private Set<ResourceModel> resources;
	
	
	/**
	 * 菜单
	 */
	@ManyToMany
	@JoinTable(
	      name="REL_ROLE_MENU",
	      joinColumns=@JoinColumn(name="ROLE_ID", referencedColumnName="ID"),
	      inverseJoinColumns=@JoinColumn(name="MENU_ID", referencedColumnName="ID"))
	@JsonIgnoreProperties("roles")
	private Set<MenuModel> menus;
	
	/**
	 * 状态(0启用1禁用)
	 */
	private String state;
	
	/**
	 * 创建人
	 */
	@OneToOne
	@JoinColumn(name="createdid")
	private AccountModel created;
	
	/**
	 * 创建时间
	 */
	@CreationTimestamp
	private Timestamp creationDate ;
	
	/**
	 * 修改时间
	 */
	@UpdateTimestamp
	private Timestamp updateDate ;
	
}
